/**
   FileServiceImpl
 * Time:2018年6月5日
 */
package com.ssm.service.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.ssm.service.FileService;
import com.ssm.util.QiniuTestUtil;

/**
 * @author 15199
 *
 */
@Service("fileService")
public class FileServiceImpl implements FileService {

	@Override
	public void fileupload(String username, MultipartFile uploadFile,
			String targetDir,HttpServletRequest request) {   
		try {
			MultipartFile file=uploadFile;
			String uploadFileName=file.getOriginalFilename();
			InputStream isRef=file.getInputStream();
			//得到真实路径
		    targetDir=request.getSession().getServletContext().getRealPath("/upload");
			//创建目标文件对象
			File targetFile=new File(targetDir,uploadFileName);
			FileOutputStream fosRef=new FileOutputStream(targetFile);
			IOUtils.copy(isRef, fosRef);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@Override
	public void qiniuFileupload(String username,
			MultipartFile uploadFile, HttpServletRequest request) throws IOException {	
		QiniuTestUtil qiniuTestUtil=new QiniuTestUtil();
		qiniuTestUtil.uploadFiles(uploadFile.getOriginalFilename(), uploadFile);
	}
}
